package com.pureut.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.SecurityUtils;
import com.pureut.system.domain.RepairFileManagement;
import com.pureut.system.domain.vo.RepairFileManagementVo;
import com.pureut.system.mapper.RepairFileManagementMapper;
import com.pureut.system.service.ISysMidSplitService;
import com.pureut.system.service.RepairFileManagementService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @ClassName RepairFileManagementServiceImpl
 * @Description: 类描述
 * @Author: try
 * @CreateDate: 2025/4/11 14:55	//创建时间
 * @UpdateUser: try
 * @UpdateDate: 2025/4/11 14:55	//更新时间
 * @UpdateRemark: 更新的信息
 * @Version: 1.0    //版本号
 */
@Service
public class RepairFileManagementServiceImpl extends ServiceImpl<RepairFileManagementMapper, RepairFileManagement> implements RepairFileManagementService
{

    @Resource
    private RepairFileManagementMapper repairFileManagementMapper;

    @Resource
    private ISysMidSplitService sysMidSplitService;

    /**
     * 上传
     * @param repairFileManagementVo
     * @return
     */
    @Override
    public boolean add(RepairFileManagementVo repairFileManagementVo) throws Exception
    {
        RepairFileManagement repairFileManagement = new RepairFileManagement();
        BeanUtil.copyProperties(repairFileManagementVo, repairFileManagement);
        repairFileManagement.setCreateTime(new Date());
        repairFileManagement.setUploader(SecurityUtils.getUsername());

        String llid = sysMidSplitService.splitStr("LLID");
        repairFileManagement.setResumeId(llid);

        String fileCode = sysMidSplitService.splitStr("FILE-CODE");
        repairFileManagement.setFileCode(fileCode);
        return save(repairFileManagement);
    }

    /**
     * 查看
     */
    @Override
    public RepairFileManagement view(String id)
    {
        return getById(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Override
    public boolean deleteBeach(List<String> ids)
    {
        return removeBatchByIds(ids);
    }

    /**
     * 修改
     * @param repairFileManagement
     * @return
     */
    @Override
    public boolean edit(RepairFileManagementVo repairFileManagement)
    {
        RepairFileManagement byId = getById(repairFileManagement.getId());
        BeanUtil.copyProperties(repairFileManagement,byId);
        byId.setUpdateBy(SecurityUtils.getUsername());
        byId.setUpdateTime(new Date());
        return updateById(byId);
    }

    /**
     * 设备维修文件管理
     * @param repairFileManagement
     * @return
     */
    @Override
    public List<RepairFileManagement> getLit(RepairFileManagementVo repairFileManagement)
    {
        return repairFileManagementMapper.getList(repairFileManagement);
    }

    /**
     * 导出
     * @param repairFileManagement
     * @return
     */
    @Override
    public List<RepairFileManagement> getInfoExport(RepairFileManagementVo repairFileManagement)
    {
        if (repairFileManagement.getIdStr() != null) {

            List<String> idList = Arrays.asList(repairFileManagement.getIdStr().split(","));

            repairFileManagement.setIds(idList);
        }

        return repairFileManagementMapper.getList(repairFileManagement);
    }
}